package main

import (
	"2302a/audio_podcast/config"
	"context"
	"log"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

func main() {

	aliyah := config.AppConf.ALiYun
	// 加载默认配置并设置凭证提供者和区域
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewStaticCredentialsProvider(aliyah.AccessKeyID, aliyah.AccessKeySecret)).
		WithRegion(aliyah.AccessCn)

	// 创建OSS客户端
	client := oss.NewClient(cfg)

	u := client.NewUploader()
	//// 创建上传器，并启用断点续传功能
	//u := client.NewUploader(func(uo *oss.UploaderOptions) {
	//	uo.CheckpointDir = "/Users/yourLocalPath/checkpoint/" // 指定断点记录文件的保存路径
	//	uo.EnableCheckpoint = true                            // 开启断点续传
	//})

	// 定义本地文件路径，需要替换为您的实际本地文件路径和文件名称
	localFile := "D:\\phpstudy_pro\\WWW\\20250616_210850.mp4"

	// 执行上传文件的操作
	result, err := u.UploadFile(context.TODO(),
		&oss.PutObjectRequest{
			Bucket: oss.Ptr("xiuluomen"),
			Key:    oss.Ptr("20250616_210850.mp4")},
		localFile)
	if err != nil {
		log.Fatalf("failed to upload file %v", err)
	}

	// 打印上传文件的结果
	log.Printf("upload file result:%#v\n", result)
}
